﻿@{
    ViewBag.Title = "问题管理";
    Layout = "~/Views/Shared/_LayoutFore.cshtml";
    var member = Session["CurrentUser"] as LY.Entity.U_Member;
}

@section script{
    <script type="text/javascript">
        (function (window, undefined, $) {
            $(document).ready(function () {
                // var mid = $('#hidMid').val();
                var gridopt = {
                    url: options.listUrl,
                    colModel: [
                        { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                        { display: '问题列表', name: 'ProjectName', width: "60%", sortable: true, align: 'left', process: processCell },
                        { display: '问题内容', name: 'Message', width: "25%", sortable: true, align: 'left', hide: true },
                        { display: '提问者', name: 'Name', width: "10%", sortable: true, align: 'left', hide: true },
                        { display: '电话号码', name: 'Phone', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '时间', name: 'CreateTime', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '回复编号', name: 'ReplyId', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '项目编号', name: 'ProjectId', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '提问人编号', name: 'MemberId', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '回复人编号', name: 'RMemberId', width: "15%", sortable: true, align: 'center', hide: true },
                        { display: '操作', name: 'Id', width: "10%", sortable: true, align: 'center', process: processOp }
                    ],
                    sortname: "CreateTime",
                    sortorder: "DESC",
                    title: false,
                    rp: 5,
                    usepager: true,
                    showcheckbox: false
                };
                var xjgrid = new xjGrid("gridlist", gridopt);

                function processCell(value, cell) {
                    var ops = [];
                    ops.push("项目名称：", value);
                    ops.push("&emsp;&emsp;提问者：", cell[3]);
                    ops.push("&emsp;&emsp;电话：", cell[4]);
                    ops.push("&emsp;&emsp;时间：", cell[5]);
                    ops.push("<br/>问题：", cell[2]);
                    ops.push("<div style='display:none;background-color:white;width:90%;' id='Detail_", cell[0], "'></div>");
                    ops.push("<div style='display:none;' id='Reply_", cell[0], "'>");
                    ops.push("<textarea style='resize:none;' maxlength='200' placeholder='请输入回复内容(200字以内)...' id='TextArea1' rows='5' cols='60'></textarea><br/>");
                    ops.push("<input class='btn' onclick=\"util.Submit('", cell[0], "','", cell[7], "','", cell[6], "','", cell[8], "')\" type='button' value='确定' />");
                    ops.push("<input class='btn'  onclick=\"util.Cancle('", cell[0], "')\" type='button' value='取消' />");
                    ops.push("</div>");

                    return ops.join("");
                }

                function processOp(value, cell) {

                    var ops = [];
                    ops.push("&nbsp;<a id='d_", cell[0], "' title='详情' href='javascript:;'  onclick=\"util.Detail('", cell[0], "','", cell[7], "','", cell[8], "')\">详情▼</a>");
                    ops.push("&nbsp;<a title='回复' href='javascript:;'  onclick=\"util.Reply('", cell[0], "')\">回复</a>");
                    ops.push("&nbsp;<a title='删除' href='javascript:;'  onclick=\"util.Delete('", cell[8], "','", cell[7], "')\">删除</a>");
                    return ops.join("");
                }
                //详情列表
                var flag = false;
                util.Detail = function (e, id, mid) {
                    if (!flag) {
                        $("#d_" + e).html("收起▲");
                        flag = true;
                        var html = "";
                        $.post("/UserProject/QuestionList", { id: id, mid: mid }, function (json) {
                            for (var i = 1; i < json.length; i++) {
                                if (json[i].RMemberId != null) {
                                    html = html + "回复：" + json[i].Message + "<br/>";
                                } else {
                                    html = html + "<b>追问：" + json[i].Message + "</b><br/>";
                                }
                            }
                            if (json.length > 1) {
                                $("#Detail_" + e).html(html).slideDown();

                            }
                        })
                    } else {
                        flag = false;
                        $("#Detail_" + e).slideUp();
                        $("#d_" + e).html("详情▼");
                    }
                }

                util.Reply = function (e) {
                    $("#Reply_" + e).slideDown();

                }

                util.Cancle = function (e) {
                    $("#Reply_" + e).slideUp().children("textarea").val("");
                }

                util.Submit = function (e, pid, rid, mid) {
                    var content = $("#Reply_" + e).children("textarea").val();
                    if (content.trim() != "") {
                        $.post("/UserProject/ReplyQuestion", {
                            rid: rid, pid: pid, mid: mid, rmid: '@member.ID', content: content
                        }, function (json) {
                            if (json.Status > 0) {
                                $.dialog.tips(json.Message, 1, 'tips.gif', function () {
                                    window.location.href = json.Data;
                                });
                            }
                            else {
                                $.dialog.tips(json.Message, 1, 'tips.gif');
                            }
                        })
                    } else {
                        $("#Reply_" + e).children("textarea").val("").focus();
                        $.dialog.tips("回复内容不允许为空哦~", 1, 'tips.gif');
                    }

                }

                util.Adopt = function (id, pid) {
                    $.post("/UserProject/AdoptQuestion", { id: id }, function (data) {
                        if (data.Status > 0) {
                            location.href = data.Data + "/" + pid;
                        } else {
                            $.dialog.tips(data.Message, 1, 'tips.gif');
                        }
                    })
                }

                util.Delete = function (mid, pid) {
                    $.dialog.confirm('确定删除该提问以及所有回复内容吗？', function () {
                        $.post("/UserProject/DeleteQuestion", { mid: mid, pid: pid }, function (data) {
                            if (data.Status > 0) {
                                $.dialog.tips(data.Message, 1, 'tips.gif');
                                location.href = data.Data;
                            } else {
                                $.dialog.tips(data.Message, 1, 'tips.gif');
                            }
                        })
                    });
                }

            });
        })(window, undefined, jQuery);
        var util = {};
        var options = {
            listUrl: "@Url.Action("QuestionManagement")"

        };
    </script>
}

<div class="RightContrent">
    <div style="margin-left: 50px; margin-right: 50px;">
       <div class="tab-content">
            <div class="line10"></div>
            <div class="line10"></div>
            <div class="tab_title">@ViewBag.Title</div>
            <div class="tab-content">
                <div style="width: 16px; height: 12px; float: left;">
                    <img src="~/Content/Images/leftarraw.png" />
                </div>
            </div>
            <div class="tab-content_border">
                <div class="u-center">
                    <div class="menu-list" align="left">
                        <a href="/UserProject/MyProject" class="btn" style="color: white">《&nbsp;返回</a>
                    </div>
                    <div class="line10"></div>
                    <div id="gridlist">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



